#pragma once

#include <string>
#include <string.h>
#include <map>
#include <list>
#include <algorithm>
#include <mutex>
#include "bondlib.h"

class BondDict{
public:
	char selective_code[32];
	char selective_content[512];
	char selective_content_en[512];
	char sortcode[4];
	char group_name[32];
	const bool operator < (const BondDict& obj) const  
	{  
		if(strcmp(group_name,obj.group_name) < 0)
			return true;
		else if(strcmp(group_name,obj.group_name) == 0 && strcmp(selective_code,obj.selective_code) <0)
			return true;
		return false;
	} 
	const bool operator == (const BondDict& obj)
	{
		if(strcmp(group_name,obj.group_name) ==0 && strcmp(selective_code,obj.selective_code) ==0)
			return true;
		return false;
	}
};

class CBondList
{
public:
	//std::list<BondDict> m_list;
	std::map<std::string, BondDict>  m_list; //<group_name.selective_code,BondDict>
};

class S_BONDLIB_EXPORT CBondDict
{
public:
	static CBondDict& instance();
public:
	CBondList *	GetBondArrByGroup(const std::string &sGroup, bool bInsert=false);
	bool	GetBondDict(const char* sGroup, const char* sCode,BondDict &stDict);

	bool	Add(BondDict &dict);
	bool	Clear( );
	int		GetSize();
	std::mutex&	GetMutex(){ return m_mutex; };
public:
	void DumpStatus(int mode = 0)const;
private:
	CBondDict();
	virtual ~CBondDict();
protected:
	std::map<std::string, CBondList*> m_map;
	std::mutex			m_mutex;
};
